package com.japanesee_learning.activity;

import com.japanesee_learning.until.ImagesUntil;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

public class KatakanaActivity extends Activity{
	
	private ImageView mImageIco;
	private TextView mTxtHeader;
	private ImageView mImageAvar;
	private ImagesUntil mObjImage;
	private Context mContext;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_katakana);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		mContext = this;
		mObjImage = new ImagesUntil(mContext);
		
		mImageIco = (ImageView)findViewById(R.id.menuViewButton);
		mTxtHeader = (TextView)findViewById(R.id.txtHeaderTitle);
		mImageAvar = (ImageView)findViewById(R.id.menuUserAvatar);
		mTxtHeader.setText(R.string.katakana);
		mImageIco.setImageResource(R.drawable.ico_kata);
		
		
		/**
		 * ====================================================================
		 * == Setting image avatar
		 * **/
		Resources resources = this.getResources();
		Uri selectedImage = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
				+ "://"
				+ resources.getResourcePackageName(R.drawable.user_avatar)
				+ '/' + resources.getResourceTypeName(R.drawable.user_avatar)
				+ '/' + resources.getResourceEntryName(R.drawable.user_avatar));

		Bitmap bitmap = mObjImage.getBitmap(selectedImage);
		bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(),
				bitmap.getHeight(), true);

		// Setting rotate following rotation of image
		Matrix matrix = new Matrix();
		matrix.postRotate(0);
		Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
				bitmap.getWidth(), bitmap.getHeight(), matrix, true);

		// Set round corner
		Bitmap roundedBitmap = mObjImage.setRoundCorner(rotatedBitmap, 35);

		// Set image into imageview
		// imageView.setBackgroundResource(R.drawable.border_imageview);
		mImageAvar.setImageBitmap(roundedBitmap);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
